<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>任务日志</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody note_reply_body">
        <el-timeline v-if="taskList.length">
          <el-timeline-item :timestamp="item.create_time" placement="top" v-for="item in taskList" :key="item.id"
                            color="#0bbd87">
            <el-card>
              <h4>执行内容：</h4>
              <p v-if="item.reply">{{ item.reply }}</p>
              <div class="common_pic_box" v-if="item.reply_pic">
                <viewerModle type="2" :imgSrc="item.reply_pic"></viewerModle>
              </div>
              <div v-if="item.file">
                <btn_file :option="{name:'附件1', src: item.file}"></btn_file>
              </div>
            </el-card>
            <el-card class="mt-10" v-if="item.evaluate">
              <h4>{{ `${item.commentuser ? item.commentuser.realname : '未知'}-` }}评价内容：</h4>
              <p v-if="item.evaluate">{{ item.evaluate }}</p>
              <div class="common_pic_box" v-if="item.evaluate_pic">
                <viewerModle type="2" :imgSrc="item.evaluate_pic"></viewerModle>
              </div>
            </el-card>
            <div style="text-align: right;padding: 10px;" v-if="!item.evaluate&&commonStatus">
              <el-link icon="el-icon-edit" @click="openCommonDialog(item)">评论</el-link>
            </div>
          </el-timeline-item>
        </el-timeline>
        <div v-else class="note-data-list">
          未找到相关数据
        </div>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">返回</el-button>
      </div>
      <taskCommonPoupe :visible.sync="teskCommon.commonvisible" :detail="editForm"
                       :commonOption="teskCommon" @getUser="getUser"
                       commonType="2" :noteId="noteId" :tabValue="tabValue"></taskCommonPoupe>
    </div>
  </div>
</template>

<script>
import taskCommonPoupe from "./taskCommonPoupe";
import {
  mapGetters
} from 'vuex';
import {taskNoteList} from '@/api/admin/task.js'

export default {
  props: ['visible', 'noteId', 'editForm', 'tabValue'], // noteId 任务人员ID
  components: {
    taskCommonPoupe
  },
  data() {
    return {
      dialogVisible: this.visible,
      taskList: [],
      teskCommon: {
        commonvisible: false,
        commonType: '',
        taskUserId: '',
        commonId: ''
      },
      commonStatus: false
    }
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        console.log('判断是否可以评价：', this.userInfo, this.editForm)
        // 发布者
        if (this.userInfo.id === this.editForm.admin_id) {
          this.commonStatus = true
        }
        // 审阅人可以评价 read_user  抄送人可以评价

        this.InitFn()
      } else {
        this.taskList = []
      }
    }
  },
  created() {
  },
  methods: {
    InitFn() {
      taskNoteList({type: this.tabValue, data: {task_user_id: this.noteId}}).then(data => {
        if (!data.code) {
          for (let item of data.list) {
            if (item.reply_pic) {
              item.reply_pic = item.reply_pic.split(',')
            }
            if (item.evaluate_pic) {
              item.evaluate_pic = item.evaluate_pic.split(',')
            }
          }
          this.taskList = data.list
        }
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    openCommonDialog(option) {
      this.teskCommon.commonId = option.id
      this.teskCommon.commonvisible = true
    },
    getUser() {
      this.InitFn()
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 450px;
  height: 65%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}

.common_pic_box {
  padding: 5px;
  background: #f4f4f4;
}

.note-data-list {
  text-align: center;
  color: #999;
  padding: 20px 0;
}
</style>


